package com.shuoyue.ycgk.ui.papergroups.adapter;

import android.text.TextUtils;

import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseViewHolder;
import com.shuoyue.ycgk.R;
import com.shuoyue.ycgk.base.baseadapter.AppBaseQuickAdapter;
import com.shuoyue.ycgk.entity.PaperSet;
import com.shuoyue.ycgk.entity.course_teacher.AppPrice;

import java.util.List;

public class PaperSetAdapter extends AppBaseQuickAdapter<PaperSet> {
    public PaperSetAdapter(@Nullable List<PaperSet> data) {
        super(R.layout.item_paper_set, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, PaperSet item) {
        helper.addOnClickListener(R.id.lay_all);
        helper.setText(R.id.title, item.getTitle());
        helper.setText(R.id.brif, item.getBrief());
        helper.setText(R.id.num, "共" + item.getTotalPaper() + "个习题包");
//        helper.setText(R.id.price, item.getIsFree() == 1
//                ? "免费" : "￥" + item.getDefaultPrice().getPrice());

        helper.setGone(R.id.free, item.getIsFree() == 1 || item.getDefaultPrice() == null);
        helper.setGone(R.id.lay_price, item.getIsFree() != 1
                && item.getDefaultPrice() != null);

        AppPrice appPrice = item.getDefaultPrice();

        if (appPrice != null) {
            helper.setGone(R.id.lay_price_org, !TextUtils.isEmpty(appPrice.getOriginalPrice()));
            helper.setGone(R.id.lay_price_vip, !TextUtils.isEmpty(appPrice.getVipPrice()));

            helper.setText(R.id.price, "￥" + appPrice.getPrice());
            helper.setText(R.id.price_org, "￥" + appPrice.getOriginalPrice());
            helper.setText(R.id.vip_price, "￥" +  appPrice.getVipPrice());
        } else {
            helper.setText(R.id.price, "");
            helper.setText(R.id.price_org, "");
            helper.setText(R.id.vip_price, "");
        }
    }
}
